package com.xian.java.stream;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * flink 获取kafka数据
 */
public class GetKafkaMsg {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //kafka properties
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers","c71:9092,c72:9092,c73:9092");
        properties.setProperty("group.id", "jemson-group"); //生产中必须加这个

        FlinkKafkaConsumer<String> flinkKafkaConsumer = new FlinkKafkaConsumer<String>("jemson-topic", new SimpleStringSchema(), properties);

        //把kafka消费到的数据加入的Flink
        DataStreamSource<String> dataStreamSource = env.addSource(flinkKafkaConsumer);

        dataStreamSource.print();


        env.execute();


    }
}
